<?php

/**
 * Created by PhpStorm.
 * User: nirui
 * Date: 17-6-29
 * Time: 下午3:21
 */
class disaster{

    /**
     * @param $warehouseid 根据仓库类型号获取主体限制条件
     * @return mixed
     */
    public static function getEnterprise_dominantLimitsInfo($condition){
        $sql='SELECT DISTINCT(`enterprise_dominant`)
FROM `enterprisedominant_limits`
WHERE `available`=1';
        if(isset($condition['warehouseid'])){
            $sql.=" AND `warehouseid` IN (".implode(',',$condition['warehouseid']).")";
        }
        if(isset($condition['export_tax_rebate'])){
            $sql.=" AND `export_tax_rebate`=".$condition['export_tax_rebate'];
        }
        return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array('enterprise_dominant');
    }

    /**
     * @param $warehouseid 根据仓库类型号获取主体限制条件
     * @return mixed
     */
    public static function getTransfer_hopper_idLimitsInfo($condition){
        $sql='SELECT DISTINCT(`transfer_hopper_id`)
FROM `enterprisedominant_limits`
WHERE `available`=1';
        if(isset($condition['warehouseid'])){
            $sql.=" AND `warehouseid` IN (".implode(',',$condition['warehouseid']).")";
        }
        if(isset($condition['export_tax_rebate'])){
            $sql.=" AND `export_tax_rebate`=".$condition['export_tax_rebate'];
        }
        return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array('transfer_hopper_id');
    }

    /**
     * @param $warehouseid 根据仓库类型号获取主体限制条件
     * @return mixed
     */
    public static function getTransfer_typeLimitsInfo($condition){
        $sql='SELECT DISTINCT(`transfer_type`)
FROM `enterprisedominant_limits`
WHERE `available`=1';
        if(isset($condition['warehouseid'])){
            $sql.=" AND `warehouseid` IN (".implode(',',$condition['warehouseid']).")";
        }
        if(isset($condition['export_tax_rebate'])){
            $sql.=" AND `export_tax_rebate`=".$condition['export_tax_rebate'];
        }
        return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array('transfer_type');
    }

    /**
     * @param $warehouseid 根据仓库类型号获取退税类型限制条件
     * @return mixed
     */
    public static function getExport_tax_rebateLimitsInfo($condition){
        $sql='SELECT DISTINCT(`export_tax_rebate`)
FROM `enterprisedominant_limits`
WHERE `available`=1';
        if(isset($condition['warehouseid'])){
            $sql.=" AND `warehouseid` IN (".implode(',',$condition['warehouseid']).")";
        }
        if(isset($condition['enterprise_dominant'])){
            $sql.=" AND `enterprise_dominant`=".$condition['enterprise_dominant'];
        }
        return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array('export_tax_rebate');
    }

    /**
     * @param $store
     * @return mixed
     */
    public static function getWarehouseidByStoreid($storeid){
        return DB::query(Database::SELECT,'SELECT `ware_id`
FROM `branch_stores`
WHERE `store_id`='.$storeid)->execute('newerp')->as_array('ware_id');
    }

    /**
     * @param $ids id数组
     * @return mixed
     */
    public static function getEnterprise_dominantsByIds($ids=array()){
        $sql=empty($ids)?'':" AND `number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorders'
AND `colum_name` LIKE 'enterprise_dominant'".$sql)->execute('newerp')->as_array('number','value');
    }

    /**
     * @param $ids id数组
     * @return mixed
     */
    public static function getTransfer_hoppersByIds($ids=array()){
        $sql=empty($ids)?'':" AND `number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorders'
AND `colum_name` LIKE 'transfer_hopper_id'".$sql)->execute('newerp')->as_array('number','value');
    }

    /**
     * @param $ids id数组
     * @return mixed
     */
    public static function getTransfer_typesByIds($ids=array()){
        $sql=empty($ids)?'':" AND `number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorders'
AND `colum_name` LIKE 'transfer_type'".$sql)->execute('newerp')->as_array('number','value');
    }

    /**
     * @param $ids 退税类型id数组
     * @return mixed
     */
    public static function getExport_tax_rebatesByIds($ids=array()){
        $sql=empty($ids)?'':" AND `number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorders'
AND `colum_name` LIKE 'export_tax_rebate'".$sql)->execute('newerp')->as_array('number','value');
    }

    /**
     * @return mixed
     * 采购单仓库类型
     */
    public static function getWarehousesByIds($ids=array()){
        $sql=empty($ids)?'':" AND `number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorders'
AND `colum_name` LIKE 'warehouse'".$sql)->execute('newerp')->as_array('number','value');
    }

    /**
     * @return mixed
     * 采购单目的仓
     */
    public static function getAllStores($ids=array()){
        $sql=empty($ids)?'':" AND `store_id` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,'SELECT DISTINCT(`store_id`),`store_name`
FROM `branch_stores`
WHERE 1 '.$sql.'
GROUP BY `store_id`')->execute('newerp')->as_array('store_id','store_name');
    }

    /**
     * @return mixed
     * 采购单付款方式
     */
    public static function getAllPayways($ids=array()){
        $sql=empty($ids)?'':" AND `id` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,'SELECT `id`,`paywayname`
FROM `payways`'.$sql)->execute('newerp')->as_array('id','paywayname');
    }

    /**
     * @return mixed
     * 采购员信息
     */
    public static function getAllPurchasers($ids=array()){
        $sql=empty($ids)?'':" AND `id` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,'SELECT `id`,`nick`
FROM `users`
WHERE 1'.$sql)->execute()->as_array('id','nick');
    }

    /**
     * @return mixed
     * 采购员信息
     */
    public static function getPurchaserNameById($id=null){
        $sql=empty($id)?'':" AND `id` =".$id;
        return DB::query(Database::SELECT,'SELECT `nick`
FROM `users`
WHERE 1'.$sql)->execute()->get('nick');
    }

    /**
     * @return mixed
     * 供应商详情
     */
    public static function getAllSuppliers($ids=array()){
        $sql=empty($ids)?'':" AND `id` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,'SELECT `id`,`name`
FROM `skusystem_suppliers`
WHERE 1'.$sql)->execute('newerp')->as_array('id','name');
    }

    /**
     * @return mixed
     * 供应商详情
     */
    public static function getSupplierNameById($id){
        $sql=empty($id)?'':" AND `id` =".$id;
        return DB::query(Database::SELECT,'SELECT `name`
FROM `skusystem_suppliers`
WHERE 1'.$sql)->execute('newerp')->get('name');
    }

    /**
     * @return mixed
     * 采购单状态
     */
    public static function getAllPurchaserorderstatuses($ids=array()){
        $sql=empty($ids)?'':" AND ` number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorders'
AND `colum_name` LIKE 'status'".$sql)->execute('newerp')->as_array('number','value');
    }

    /**
     * @return mixed
     * 采购单审核状态
     */
    public static function getAllPurchaserorderpassstatuses($ids=array()){
        $sql=empty($ids)?'':" AND ` number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorder_details'
AND `colum_name` LIKE 'pass'".$sql)->execute('newerp')->as_array('number','value');
    }

    /**
     * @return mixed
     * 采购单付款币种
     */
    public static function getAllPurchaserordercoins($ids=array()){
        $sql=empty($ids)?'':" AND ` number` IN (".implode(',',$ids).")";
        return DB::query(Database::SELECT,"SELECT `number`,`value`
FROM `statusdics`
WHERE `table`
LIKE 'purchaseorder_details'
AND `colum_name` LIKE 'transfer_type'".$sql)->execute('newerp')->as_array('number','value');
    }

}